package com.uplooking.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.uplooking.service.RepairService;

@Controller
public class RepairController {

	@Autowired
	private RepairService repairService;

	@RequestMapping(value = "/repair/index", method = RequestMethod.GET)
	public String methodRepair1() {
		return "service/repair";
	}

	@ResponseBody
	@RequiresPermissions("repair!list")
	@RequestMapping(value = "/repair/list", method = RequestMethod.GET, produces = { "application/json;charset=utf-8" })
	public String methodRepair2(String rrbsno, int index, int size, int step) throws Exception {
		return JSONObject.toJSONString(repairService.getRepairList(rrbsno, index, size, step));
	}

	@ResponseBody
	@RequiresPermissions("repair!add")
	@RequestMapping(value = "/repair/add", method = RequestMethod.POST, produces = { "application/json;charset=utf-8" })
	public String methodRepair3(String rnrtid, String[] rrproblem, int rrcost, String rrdesc) throws Exception {
		return JSONObject.toJSONString(repairService.addRepair(rnrtid, rrproblem, rrcost, rrdesc));
	}

	@ResponseBody
	@RequiresPermissions("repair!ok")
	@RequestMapping(value = "/repair/ok", method = RequestMethod.GET, produces = { "application/json;charset=utf-8" })
	public String methodRepair4(int rrid, String rrbsno) throws Exception {
		return JSONObject.toJSONString(repairService.repairOk(rrid, rrbsno));
	}
}
